/* rcoqtysq.p - DETERMINE OPEN QUANTITY FOR A SEQUENCE ORDER LINE             */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.16 $                                                        */
/*V8:ConvertMode=NoConvert                                                    */
/* REVISION: 9.1            CREATED: 06/04/99  BY: *N003* Patrick Rowan       */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00  BY: *N0KP* Mark Brown          */
/* Revision: 1.15      BY:Patrick Rowan        DATE:07/05/00   ECO: *N0F6*    */
/* $Revision: 1.16 $    BY: Jean Miller         DATE: 03/22/01  ECO: *P008*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: Logic to determine the customer sequences that have not been
              placed on pre-shippers and/or shipped.

 ============================================================================
 !*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

{mfdeclre.i}

/*INPUT PARAMETERS*/
define input parameter sod_recid as recid.

/*OUTPUT PARAMETERS*/
define output parameter open_qty like sod_qty_ord.

define new shared variable l_inc_wkend_shpcal  like so_incl_iss no-undo.

/*LOCAL VARIABLES*/
define variable cum_net_req as decimal no-undo.
define variable net_req as decimal no-undo.
define variable prior_cum_net_req as decimal no-undo.
define variable ship_cmplt as decimal no-undo.
define variable cum_all_qty as decimal no-undo.
define variable shipfrom_date as date no-undo.
define variable shipfrom_time as character no-undo.
define variable arrive_date as date no-undo.
define variable arrive_time as character no-undo.
define variable ret_status as character no-undo.
define variable translt_days like sod_translt_days no-undo.

{sosqvars.i}

find sod_det where recid(sod_det) = sod_recid no-lock.
find so_mstr where so_nbr = sod_nbr no-lock.

assign
   open_qty   = 0
   l_inc_wkend_shpcal = so_incl_iss
   translt_days = decimal(substring(so_conrep,2,6)).

for first rcs_mstr where
          rcs_shipfrom    = so_site and
          rcs_shipto      = so_ship and
          rcs_active
no-lock: end.

if available(rcs_mstr) then do:

   for each rcsd_det where
            rcsd_shipfrom   = rcs_shipfrom  and
            rcsd_shipto     = rcs_shipto    and
            rcsd_rlse_id    = rcs_rlse_id   and
            rcsd_part       = sod_part      and
            rcsd_order      = sod_nbr       and
            rcsd_line       = sod_line      and
            (not rcsd_picked)               and
            (not rcsd_delete)               and
            (not rcsd_x_referenced)
   no-lock:

      /* DETERMINE SHIPPING DATES FROM SHIP/DELIVERY FLAG */
      if rcs_date_type then
         /* SHIP DATES */
         assign
            shipfrom_date = rcsd_date
            shipfrom_time = rcsd_time.
      else do:
         /* DELIVERY DATES */
         {gprun.i ""rcshipdt.p""
            "(input rcsd_shipfrom,
              input rcsd_shipto,
              input rcsd_date,
              input rcsd_time,
              input translt_days,
              output shipfrom_date,
              output shipfrom_time,
              output arrive_date,
              output arrive_time,
              output ret_status)"}

      end.  /* else do */

      /* Logic: Consider first_time only for schedules on first_date,
       * and last_time only for schedules on the last_date.
       * If the schedule is between the first_date and last_date,
       * then ignore the times. If the first_date and last_date coincide, then
       * consider both times to select schedules.
       * Some apparently redundant logic like
       * schd_date = first_date and schd_date < last_date
       * is required to catch user entering first_date which is
       * greater than the last_date */

      if rcsd_discr_qty <> 0 and
         (shipfrom_date  > s_due_date     or
         (shipfrom_date  = s_due_date and shipfrom_time >= s_due_time))
         and
         (shipfrom_date  < s_due_date1    or
         (shipfrom_date  = s_due_date1 and shipfrom_time <= s_due_time1))
         and
         rcsd_cust_job >= s_job  and
         rcsd_cust_job <= s_job1
         and
         rcsd_cust_seq >= s_seq  and
         rcsd_cust_seq <= s_seq1
         and
         rcsd_cust_ref >= s_ref  and
         rcsd_cust_ref <= s_ref1
         and
         rcsd_dock >= s_dock   and
         rcsd_dock <= s_dock1
         and
         rcsd_line_feed >= s_line_feed   and
         rcsd_line_feed <= s_line_feed1
         and
         rcsd_status = s_status
      then
         open_qty = open_qty + rcsd_discr_qty.

   end.  /* for each rcsd_det where */

end.  /* if available(rcs_mstr) */
